package com.projects.android.dto;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class RestaurantDTO {
	private int ID;
	private int IDDistrict;
	private int IDFoodType;
	private int IDManager;
	private String Name;
	private int EstimatedServiceTime;
	private String DeliveryDistricts;
	private String TimeStart;
	private String TimeEnd;
	private String Address;
	private String Image;
	private ArrayList<MenuDTO> Menus;
	private String ContentType;

	public String toString() {
		return Name;
	}

	public void initObject(JSONObject data) {
		try {
			ID = Integer.valueOf(data.getString("ID"));
			IDDistrict = Integer.valueOf(data.getString("IDDistrict"));
			IDFoodType = Integer.valueOf(data.getString("IDFoodType"));
			
			if (!data.getString("EstimatedServiceTime").equals("")){
				EstimatedServiceTime = Integer.valueOf(data
						.getString("EstimatedServiceTime"));
			}
			
			Name = data.getString("Name");
			DeliveryDistricts = data.getString("DeliveryDistricts");
			TimeStart = data.getString("TimeStart");
			TimeEnd = data.getString("TimeEnd");
			Address = data.getString("Address");
			Image = data.getString("Image");
			ContentType = data.getString("ContentType");
			
			Menus = new ArrayList<MenuDTO>();
			JSONArray arrData = new JSONArray(data.getString("Menus"));
			// Loop for all reveived objects
			for (int i = 0; i < arrData.length(); i++) {
				JSONObject dataChild = (JSONObject) arrData.get(i);
				MenuDTO dto = new MenuDTO();
				dto.initObject(dataChild);
				Menus.add(dto);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			Log.e("Init RestaurantDTO", e.toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e("Init RestaurantDTO", e.toString());
		}
	}

	public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}

	public int getIDDistrict() {
		return IDDistrict;
	}

	public void setIDDistrict(int iDDistrict) {
		IDDistrict = iDDistrict;
	}

	public int getIDFoodType() {
		return IDFoodType;
	}

	public void setIDFoodType(int iDFoodType) {
		IDFoodType = iDFoodType;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public int getEstimatedServiceTime() {
		return EstimatedServiceTime;
	}

	public void setEstimatedServiceTime(int estimatedServiceTime) {
		EstimatedServiceTime = estimatedServiceTime;
	}

	public String getDeliveryDistricts() {
		return DeliveryDistricts;
	}

	public void setDeliveryDistricts(String deliveryDistricts) {
		DeliveryDistricts = deliveryDistricts;
	}

	public String getTimeStart() {
		return TimeStart;
	}

	public void setTimeStart(String timeStart) {
		TimeStart = timeStart;
	}

	public String getTimeEnd() {
		return TimeEnd;
	}

	public void setTimeEnd(String timeEnd) {
		TimeEnd = timeEnd;
	}

	public String getImage() {
		return Image;
	}

	public void setImage(String image) {
		Image = image;
	}

	public ArrayList<MenuDTO> getMenus() {
		return Menus;
	}

	public void setMenus(ArrayList<MenuDTO> menus) {
		Menus = menus;
	}

	public String getContentType() {
		return ContentType;
	}

	public void setContentType(String contentType) {
		ContentType = contentType;
	}

	public int getIDManager() {
		return IDManager;
	}

	public void setIDManager(int iDManager) {
		IDManager = iDManager;
	}

	public String getAddress() {
		return Address;
	}

	public void setAddress(String address) {
		Address = address;
	}
}
